using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    public enum GameState { GamePlay, Menu, GameOver } //emum para controlar o estado do jogo

    public class GameManager : Microsoft.Xna.Framework.Game
    {     
        GraphicsDeviceManager graphics;
        public SpriteBatch spriteBatch;

        public static GameState currentGameState;// variavel pra acessar o enum
        public static GameManager self;//variavel pra instanciar essa classe pelas outras

        Menu menu;
        GamePlay gamePlay;

        public GameManager() //constructor
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            Window.Title = "Pong do Phil";
            self = this;

        }
        protected override void Initialize()
        {
            currentGameState = GameState.Menu;//define o estado do jogo como Menu

            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            menu = new Menu();
            gamePlay = new GamePlay();
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            /*if (currentGameState == GameState.Menu) 
            {
                menu.Update(gameTime);//chama o update do menu, se o estado for o menu
            }*/

            if (currentGameState == GameState.GamePlay)
            {
                gamePlay.Update();//chama o update do gameplay, se o estado for o gameplay

                //TO DO: sistema e tela de pause
                if (Keyboard.GetState().IsKeyDown(Keys.Escape))//dentro do gameplay, se o jogador apertar "Esc", fecha o game
                    this.Exit();
            }
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            if (currentGameState == GameState.Menu)
                menu.Draw(spriteBatch); //chama o Draw do menu, se o estado for o menu

            else
            if (currentGameState == GameState.GamePlay)
            {
                gamePlay.Draw(spriteBatch);//chama o draw do GamePlay, se o estado for o GamePlay
                GraphicsDevice.Clear(Color.White);//seta a cor de fundo do gameplay como branca

            } 
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
